﻿/*
 * Monti
 * Created by: Jonathan Montiverdi
 * Date: 7/23/2012
 * License: http://jonathan.codeplex.com/license
 */
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;

namespace Monti.Controls
{
   /// <summary>
   /// Description of DropDownButton.
   /// TODO: Add style that draws a down arrow.
   /// </summary>
   public class DropDownButton : ToggleButton
   {
      /// <summary>
      /// Initializes a new drop down button.
      /// </summary>
      public DropDownButton()
      {
         this.SetBinding (IsCheckedProperty, new Binding ("DropDown.IsOpen") { Source = this });
      }
      
      /// <summary>
      /// Dependency property for the drop down part of the button.
      /// </summary>
      public static readonly DependencyProperty DropDownProperty =
         DependencyProperty.Register("DropDown", typeof(ContextMenu), typeof(DropDownButton),
                                     new UIPropertyMetadata(null));
      
      /// <summary>
      /// Gets or Sets the context menu used for the drop down.
      /// </summary>
      public ContextMenu DropDown
      {
         get { return (ContextMenu) GetValue (DropDownProperty); }
         set { SetValue (DropDownProperty, value); }
      }
      
      /// <summary>
      /// Occurs when the users click this button.
      /// </summary>
      protected override void OnClick()
      {
         if (this.DropDown != null)
         {
            this.DropDown.PlacementTarget = this;
            this.DropDown.Placement = PlacementMode.Bottom;
            this.DropDown.IsOpen = true;
         }
      }
   }
}
